using System;
using System.Windows;
using System.Windows.Controls;
using System.Collections.Generic;
using Silvery.Data;
namespace RoleEditer
{
    public class TreeViewItem_Spirite : TreeViewItem
    {
        public SpiritFile_Frames Spirtfile_Fames { get; set; }
        public TreeViewItem_Spirite(string headname)
        {
            Header = headname;
            Tag = "spirit";

            Spirtfile_Fames = new SpiritFile_Frames();
            Spirtfile_Fames.Millisecond = 33;
            var button = new Button() { Content = "新建动画" };
            button.Click += new RoutedEventHandler(aniitem_button_Click);
            Items.Add(button);
        }
        public void UpDataSpirit()
        {
            
        }
        public string SpiritName
        {
            get
            {
                return Header as string;
            }
        }
        void aniitem_button_Click(object sender, RoutedEventArgs e)
        {
            SpiritGroupNew groupnew = new SpiritGroupNew();
            groupnew.Closed += new EventHandler(groupnew_Closed);
            groupnew.Show();
        }
        //组创建完成的窗口关闭事件
        void groupnew_Closed(object sender, EventArgs e)
        {
            var groupnew = sender as SpiritGroupNew;
            groupnew.Closed -= groupnew_Closed;
            
            if (groupnew.DialogResult == true)
            {
                if (ContainsAniname(groupnew.aniname.Text))
                    MessageBox.Show("这个动画名字已经存在了");
                else
                {
                    TreeViewItem_Animat item = new TreeViewItem_Animat(groupnew.aniname.Text);
                    this.Items.Insert(this.Items.Count - 1, item);
                    SpiritManager.Instance[this].Add(item.AnimatName, new List<Image>());
                    
                }
            }
        }
        bool ContainsAniname(string aniname)
        {
            foreach (var item in SpiritManager.Instance[this])
            {
                if (item.Key == aniname)
                    return true;
            }
            return false;
        }
    }
}
